
package br.ufscar.sor.ppgccs.educatransito.fachada;

import br.ufscar.sor.ppgccs.educatransito.entidade.Usuario;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Joaquim
 */
@Stateless
public class UsuarioFacade extends AbstractFacade<Usuario> {
    @PersistenceContext(unitName = "EducaTransitoPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsuarioFacade() {
        super(Usuario.class);
    }
    
        public Usuario efetuarLogin(String login, String senha) {
        try {
            return (Usuario) em.createQuery("select u from Usuario as u where u.login = '" + login + "'"
                    + " and u.senha = '" + senha + "'").getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }
    
}
